<?php
class StockLogAction extends SecurityAction{
	function _initialize(){
		$this->assign("menuFirst",session('menuFirst'));
		$this->assign("menuSecond",session('menuSecond'));
	}

	function slist(){
		$ob = M("yq_logs");
		
		if($_GET['shopid']){
			$sql[] = array('a.shopid'=>$_GET['shopid']);
		}

		if($_GET['type']){
			$sql[] = array('yq_logs.type'=>$_GET['type']);
// 			$sql['yq_logs.type'] = $_GET['type'];  2种写法
		}
		
// 		$sql[] = "yq_logs.type != 0";  //查询库存领用、库存耗损的日志
		$sql["yq_logs.type"] = array("neq","0"); //2种写法
		
		$cpp = 30; //分页数
		import('ORG.Util.Page');// 导入分页类
		$count      = $ob->join(" yq_stock a on a.tid = yq_logs.stockid ")
						 ->join(" yq_shop b on yq_logs.shopid = b.tid ")
						 ->join(" yq_goods c on a.goodsid = c.tid ")
						 ->join(" yq_member d on d.tid = yq_logs.memberid ")
						 ->field(" yq_logs.*,b.shopname,c.goods_code,c.goods_name,d.realname  ")
						 ->where($sql)->count();// 查询满足要求的总记录数
		$Page       = new Page($count,$cpp);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		
		$list = $ob->join(" yq_stock a on a.tid = yq_logs.stockid ")
				 	->join(" yq_shop b on yq_logs.shopid = b.tid ")
					->join(" yq_goods c on a.goodsid = c.tid ")
					->join(" yq_member d on d.tid = yq_logs.memberid ")
				 	->field(" yq_logs.*,b.shopname,c.goods_code,c.goods_name,d.realname ")
				  	->where($sql)->limit($Page->firstRow.','.$Page->listRows)->select();
		
		$ob = M("yq_shop");
		$shoplist = $ob->where(array("is_forbit"=>"1"))->select();
		
		$this->assign("list", $list);
		$this->assign("shoplist", $shoplist);
		$this->assign('show',$show);// 赋值分页输出
		
		$this->display("/StockLog/slist");
	}
}	

?>